package com.mib.browser;

import javax.swing.table.AbstractTableModel;
import java.util.Vector;

public class OperationTableModel extends AbstractTableModel {
    private Vector operationResults = new Vector();
    private String[] columnNames = new String[]{"OID", "Value值"};

    public OperationTableModel() {
    }

    public int getColumnCount() {
        return this.columnNames.length;
    }

    public int getRowCount() {
        return this.operationResults.size();
    }

    public String getColumnName(int col) {
        return this.columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        if (row >= this.operationResults.size()) {
            return null;
        } else {
            OperationResult r = (OperationResult)this.operationResults.elementAt(row);
            return col == 0 ? r.getOid() : r.getValue();
        }
    }

    public Class getColumnClass(int c) {
        return this.getValueAt(0, c).getClass();
    }

    public boolean isCellEditable(int row, int col) {
        return false;
    }

    public void setValueAt(Object value, int row, int col) {
    }

    public void clearAll() {
        this.operationResults.removeAllElements();
        this.fireTableDataChanged();
    }

    public void addOperationResult(OperationResult r) {
        this.operationResults.insertElementAt(r, 0);
        this.fireTableDataChanged();
    }
}
